<section class="section {page->class}">
	<h2 class="hide">{page->title}</h2>
	<script>
		$(function() {
			{? script}
				{@ script}
			$.getScript('{CFG->PATH->JS}/{.value_}');
				{/}
			{/}
						
			{? binfo->ba_category}
			$("#{module}_category > option[value='{result->bc_seq}']").attr("selected", "selected");
			{/}
			
			
			// script를 읽어와서 하기 때문에 반드시 셋타임 아웃을 해줘야됨.
			setTimeout(function(){
				//$('textarea.wysiwyg').elrte(opts);
				$('textarea.wysiwyg').tinymce($.extend(aktimemce));
	
				
				// 포커스가 wysiwyg 쪽으로 이동하기 때문에 젤 처럼 element로 포커스 다시 이동시키기
				$("#{module}_subject").focus();
				
				
				{? binfo->ba_attach}
					$("#{module}_fileupload").pluploadQueue({
						// General settings
						 runtimes : 'html5,gears'
						,url : '/default/doFileUpload'
						,max_file_size : '10mb'
						,chunk_size : '10mb'
						,filters : [
							{title : "Image files", extensions : "jpg,gif,png"},
							{title : "Zip files", extensions : "zip"},
							{title : "PDF files", extensions : "pdf"}
						]
			
						// Resize images on clientside if we can
						,resize : {width : 320, height : 240, quality : 90}
						
						,init : {
							FileUploaded: function(up, file, info) {
								 // seq값 받아와서 hidden column에 때려 넣어야함.
								 info = $.parseJSON(info.response);
									 
								 if($("#{module}_files").val() != "") {
									 files = $("#{module}_files").val(); 
									 $("#{module}_files").val(files+","+info.result.seq);
								 } else {
									 $("#{module}_files").val(info.result.seq)
								 }
							}
							,FilesAdded : function(up, file) {
								up.start();
							}
						}
					});
						
					//  크롬 및 사파리에서는 파일 업로드 버튼이 정상적으로 클릭이 안됨.
					$('#{module}_fileupload > div.plupload').css('z-index','1010');
						
						
					// 서브밋시 파일업로드가 안된거 있으면 추가 시키기
					$("#{module}_add").validate({
						submitHandler : function(form) {
							var uploader = $('#{module}_fileupload').pluploadQueue();
							
							if(uploader.total.uploaded != uploader.files.length) {
								alert('업로드 완료 후 저장하실수 있습니다.');
								return false;
							} else {
								$.ajax({
									 url : form.action
									,data : $(form).serialize()
									,success:function(data){
										if(data.code == mesg.success) {
											
											sagapo.article_refresh(data.return_url);
											
											// 리스트 페이지에서 변경된 값 바꿔주기
											var subject = $(".subject_{result->b_seq}");
											if(subject.length > 0) {
												subject.text($("#{module}_subject").val());	
											}
											
										} else {
											alert(data.msg);
										}
										
										return false;
									}
								});	
							}
							return false;
						}
					});
				{:}
					$("#{module}_add").validate();
				{/}
		
			},500);
			
			
			$("#{module}_add button[type='submit']").click(function() {
				tinyMCE.triggerSave();
			});
		});
	</script>
	
	<form name="{module}_add" id="{module}_add" method="post" action="{action}/doModify">
		<table class="table">
			<caption>
				{page->title}
			</caption>
			<colgroup>
				<col class="add" />
				<col />
			</colgroup>
			<tbody>
				{? binfo->ba_category}
				<tr>
					<th scope="row" class="txt_right br"><label for="{module}_category">카테고리</label></th>
					<td>
						<select name="{module}_category" id="{module}_category">
							{@ category}
							<option value="{.value_->bc_seq}">{.value_->bc_name}</option>
							{/}
						</select>
						<input type="hidden" name="{module}_ocategory" value="{result->bc_seq}" />
					</td>
				</tr>
				{/}
				<tr>
					<th scope="row" class="txt_right br"><label for="{module}_subject">제목</label></th>
					<td>
						<input type="text" name="{module}_subject" id="{module}_subject" class="subject required" placeholder="제목" value="{result->b_subject}" />
						<input type="hidden" name="{module}_bid" value="{binfo->ba_id}" />
						<input type="hidden" name="{module}_seq" value="{result->b_seq}" />
					</td>
				</tr>
				<tr>
					<th scope="row" class="txt_right br"><label for="{module}_content">내용</label></th>
					<td>
						<textarea id="{module}_content" name="{module}_content" class="wysiwyg required" cols="70" rows="10" placeholder="내용">{result->b_content}</textarea>
					</td>
				</tr>
				{? binfo->ba_attach}
				<tr>
					<th scope="row" class="txt_right br">첨부파일</th>
					<td>
						{? attach->is}
						<ul class="old_attach">
							{@ attach->list}
							<li>
								<input type="checkbox" name="{module}_remove_files[]" value="{.value_->a_seq}" id="remove_file_{.value_->a_seq}" />
								<label for="remove_file_{.value_->a_seq}">{.value_->a_filename}</label>
							</li>
							{/}
						</ul>
						{/}
						<div id="{module}_fileupload" class="fileupload">
							You browser doesn't support native upload. Try Firefox 3 or Safari 4.
						</div>
						
						<input type='text' name="{module}_files" id="{module}_files" />
					</td>
				</tr>
				{/}
			</tbody>
		</table>
		<div class="button_area">
			<button type="submit">전송</button>
			<button type="button" class="cancel" onclick="history.back(-1)">뒤로</button>
		</div>
	</form>
</section>